home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-11 | 5.2 KB | 193 lines | [TEXT/PJMM] |
- program Update;
-
- { Resource carrier copies its resources to selected target file. }
-
- var
- Convert: boolean;
-
- {----------------------------------------------------------------- }
-
- procedure ShowRunWindow (var runWindow: WindowPtr; var oldPort: GrafPtr);
-
- var
- rBounds: rect;
-
- begin
- SetCursor(GetCursor(watchCursor)^^);
- GetPort(oldPort);
- if runWindow = nil then
- begin
- SetRect(rBounds, 15, 50, 190, 95); {left, top, right, bottom}
- runWindow := NewWindow(nil, rBounds, 'Update', false, 0, POINTER(-1), false, longint('Pete'));
- end;
- SetPort(runWindow);
- ShowWindow(runWindow);
- textFont(Geneva);
- textSize(9);
- ForeColor(blueColor);
- MoveTo(9, 14);
- DrawString('Update ©1991 by Pete Johnson');
- MoveTo(9, 26);
- DrawString('Glassell Park BBS (213) 254-4852');
- MoveTo(9, 38);
- ForeColor(redColor);
- DrawString('Now copying ')
- end;
-
- {----------------------------------------------------------------- }
-
- procedure HideRunWindow (var runWindow: WindowPtr; var oldPort: GrafPtr);
-
- begin
- HideWindow(runWindow);
- SetPort(oldPort);
- InitCursor
- end;
-
- {----------------------------------------------------------------- }
-
- procedure SwapResources (theType: resType; SourceFRef, TargetFRef, rezCount: integer);
-
- var
- count: integer;
- hRsrc, hOldRsrc: handle;
- rID: integer;
- rType: resType;
- rName: str255;
-
- begin
- UseResFile(SourceFRef);
- for count := 1 to rezCount do
- begin
- hRsrc := Get1IndResource(theType, count);
- if hRsrc <> nil then
- begin
- GetResInfo(hRsrc, rID, rType, rName);
- if (rName <> 'don’t install') then { don't install reserved resources }
- begin
- DetachResource(hRsrc);
- UseResFile(TargetFRef);
- if Convert & (rType = 'ICON') & (rName <> 'don’t convert') then { change to FICN unless marked }
- rType := 'FICN';
- hOldRsrc := Get1Resource(rType, rID);
- if hOldRsrc <> nil then
- begin
- RmveResource(hOldRsrc);
- {• UpdateResFile(TargetFRef);•}
- DisposHandle(hOldRsrc);
- hOldRsrc := nil;
- end; {if hOldRsrc <> nil}
- AddResource(hRsrc, rType, rID, rName);
- if ResError = NoErr then
- WriteResource(hRsrc);
- end; { if (rName <> 'don’t install') }
- DetachResource(hRsrc);
- DisposHandle(hRsrc);
- hRsrc := nil;
- end; { if hRsrc <> nil }
- UseResFile(SourceFRef);
- end {for count := 1 to rezCount}
- end;
-
- { -------------------------------------------------------------------------------- }
-
- function ClipString (inString: str255; len: integer): str255;
-
- { Sets string length to len }
-
- begin
- inString := copy(inString, 1, len); { make sure it's not longer than len characters }
- while length(inString) < len do { make sure it's not shorter than len characters }
- inString := concat(inString, ' ');
- ClipString := inString
- end;
-
- { -------------------------------------------------------------------------------- }
-
- procedure GetFileTypes (var typeList: SFTypeList; var numTypes: integer);
-
- var
- counter: integer;
- fileType: str255;
-
- begin
- numTypes := 0;
- for counter := 1 to 4 do
- begin
- GetIndString(fileType, 32001, counter);
- if fileType <> '' then { if it's empty, there are no more STR#s }
- begin
- numTypes := succ(numTypes);
- typeList[pred(counter)] := ClipString(fileType, 4)
- end
- else if numTypes = 0 then {if empty string and numTypes still 0, make -1 to show all files}
- numTypes := -1
- end
- end;
-
- { -------------------------------------------------------------------------------- }
-
- var
- Err: OSErr;
- where: point;
- reply: SFReply;
- typeList: SFTypeList;
- rezType, tempString: str255;
- SourceRezRef, DestRezRef, counter, numTypes, rezCount: integer;
- finished: boolean;
- runWindow: WindowPtr;
- oldPort: GrafPtr;
- PenLoc: point;
- theRect: rect;
-
- begin
- MaxApplZone;
- InitCursor;
- runWindow := nil;
- SourceRezRef := CurResFile;
- GetFileTypes(typeList, numTypes);
- GetIndString(tempString, 32002, 1);
- UprString(tempString, false);
- if tempString[1] = 'Y' then
- Convert := true
- else
- Convert := false;
- finished := false;
- while not finished do
- begin
- SetCursor(arrow);
- counter := 0;
- SFPGetFile(where, '', nil, numTypes, typeList, nil, reply, 32000, nil);
- if reply.good then
- begin
- ShowRunWindow(runWindow, oldPort);
- GetPen(PenLoc);
- SetRect(theRect, PenLoc.h, PenLoc.v - 9, PenLoc.h + 75, PenLoc.v);
- DestRezRef := HOpenResFile(reply.vRefNum, 0, reply.fName, fsRdWrPerm);
- if DestRezRef <> -1 then
- repeat
- UseResFile(SourceRezRef);
- counter := succ(counter);
- GetIndString(rezType, 32000, counter);
- if (rezType <> '') then { if it's not empty, STR# is valid }
- begin
- rezType := ClipString(rezType, 4);
- rezCount := Count1Resources(rezType);
- if (rezCount > 0) then
- begin
- MoveTo(PenLoc.h, PenLoc.v);
- EraseRect(theRect);
- DrawString(concat(rezType, ' resources'));
- SwapResources(rezType, SourceRezRef, DestRezRef, rezCount)
- end
- end
- until rezType = '';
- CloseResFile(DestRezRef);
- HideRunWindow(runWindow, oldPort)
- end { if reply.good }
- else
- finished := true
- end; { while not finished }
- if runWindow <> nil then
- DisposeWindow(runWindow)
- end.